package link;

public class ListReverse {
    public static Node reverseList(Node head){
        Node prev = null;
        Node next = null;
        while(head!=null){
            next = head.next;
            head.next = prev;
            prev = head;
            head = next;
        }
        return prev;
    }

    public static Node reverse2(Node node){

        Node prev = null;
        Node next = null;
        while(node!=null){
            next = node.next;
            node.next = prev;
            prev = node;
            node = next;
        }
        return prev;

    }


    public static void main(String[] args){
         Node node =new Node(0);
         Node head = node;
         Node tail = node;
         for(int i=0;i<10;i++){
             Node nodeT = new Node(i);
             tail.next = nodeT;
             tail = nodeT;
         }
       Node nodeR =  reverse2(node);
         System.out.println(nodeR);


    }


}
